<?php
// 本文档自动生成，仅供测试运行
class UserAction extends BaseAction
{
    /**
    +----------------------------------------------------------
    * 默认操作
    +----------------------------------------------------------
    */
    public function index()
    {
        //$NbSite	= M("User");
		//$strJumpUrl = APP_NAME."://Mmp/";
		//var_dump(U($strJumpUrl));
		/*import("@.ORG.Page"); //导入分页类
                $count = $NbSite->count();    //计算总数
                $p = new Page ( $count, 5 );
		$list=$NbSite->limit($p->firstRow.','.$p->listRows)->order('site_id desc')->select();
		$p->setConfig('header','个网站');
		$p->setConfig('prev',"[上一页]");
		$p->setConfig('next','[下一页]');
		$p->setConfig('first','[第一页]');
		$p->setConfig('last','[末页]');
		$page = $p->show ();*/
		//$this->assign( "page", $page );
		//$this->assign ( "list", $list );
		$this->display();
        
    }
	
	

    	// 处理表单数据
	public function reg() {
		/*$Form	=	D("User");
		if($Form->create()) {
			if(false !==$Form->add()) {
    			$this->success('注册成功');
            }else{
                $this->error('数据写入错误');
            }
		}else{
			$this->error($Form->getError());
		}*/
		$this->display();
	}
	
	public function appenduser() {
		$User	=	D("User");
		if($User->create()) {
			$intID = $User->add();
			if(false !==$intID) {
				$arrRow = $User->where("user_id='".$intID."'")->select();
				$arrRow = $arrRow[0];
				$strSiteUrl = C('site_url');
				$strSiteUrl = "http://" . $strSiteUrl;
				$strUrl = U('Home://User/vemail/key/') . $arrRow['email_key'];
				$strUrl .= "/user/" . $arrRow['user_name'];
				$strUrl = $strSiteUrl . $strUrl;
				$strMailto = $arrRow['user_email'];
				$strSubject = "爱帮买邮箱验证";
				$strContent = "此邮件为爱帮买的邮件验证系统自动发送，<a href='$strUrl' >点击此处进行验证您的邮件地址</a>，或复制以下链接至新浏览器窗口进行邮件地址的验证操作。<br/>$strUrl";
				SmtpSendMail($strMailto,$strSubject,$strContent);
				$strJumpUrl = U("Home://Index");
				$this->assign ( "jumpUrl", '' );
				$this->assign ( "waitSecond", 1000 );
				$this->assign ( "msgTitle", "用户注册成功，等待邮件验证。" );
    			$this->success('您好，您已成功注册成为本站会员，我们已向您注册的电子邮箱发送验证邮件，请您查看该邮件，并点击邮箱验证链接进行邮箱验证。');
            }else{
                $this->error('数据写入错误');
            }
		}else{
			$this->error($User->getError());
		}
		//$this->display();
	}

	//邮箱验证
	public function vemail()
	{
		if($_GET['user']!='' || $_GET['key']!='') //验证邮箱链接有参数
		{
			$user = $_GET['user'];
			$key = $_GET['key'];
			$User = D('User');
			$count = $User->where("email_key = '$key' and user_name = '$user'")->count();
			if($count > 0) //验证邮箱链接参数正确
			{
				//更新数据库
				$data['email_key'] = '';
				$data['email_activation'] = 1;
				$User->where("email_key = '$key' and user_name = '$user'")->save($data);
				//呈现信息
				$strJumpUrl = U("Home://Index");
				$this->assign ( "jumpUrl", U($strJumpUrl) );
				$this->assign ( "waitSecond", 1000 );
				$this->assign ( "msgTitle", "用户注册成功，等待邮件验证。" );
    			$this->success('您好，您注册的电子邮箱已成功验证。');
            }
			else
			{
				$this->error('邮箱验证失败，请重新验证邮箱。');
			}
		}
		else
		{
			$this->error('邮箱验证失败，请重新验证邮箱。');
		}
	}
	
    // 用户登录
    public function login()
    {
		$passport = getpassport($_POST['user_email'], $_POST['user_password']);
		//var_dump($passport);
		//exit();
		if(!is_array($passport))
		{
			if(-1==$passport)
            {
				$this->error('用户不存在');
            }
			if(-2==$passport)
            {
                $this->error('密码错误');
            }
        }
		else
		{
			checkauth();
			$strJumpUrl = APP_NAME."://Mmp/";
			$this->assign ( "jumpUrl", U($strJumpUrl) );
			$this->success('登陆成功');
		}
    }
	
	public function AddItem()
	{
		
	}
	
    /**
    +----------------------------------------------------------
    * 探针模式
    +----------------------------------------------------------
    */
    public function checkEnv()
    {
        load('pointer',THINK_PATH.'/Tpl/Autoindex');//载入探针函数
        $env_table = check_env();//根据当前函数获取当前环境
        echo $env_table;
    }

}
?>